<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>欢迎访问产品运营互动中心！</title>
		<link rel="stylesheet" href="<s:url value="/css/style_new.css"/>">
		<script type="text/javascript"
			src="<s:url value="/script/easyajax.js"/>"></script>
		<script>
/*产品目录ID*/
var id="${productRefSort.sort}";
/*实例化产品结果集脚本对象*/
var productAjax=new AjaxObj();
var refAjax=new AjaxObj();
function initPage(){
    getRef();
	getProduct();
}
/*查询所有产品*/
function getProduct(){
    for(i=$("productId").options.length-1;i>-1;i--){
    	$("productId").remove(i);
    }
    var url="<s:url value="/business/product/viewProduct.action"/>";
    if(form1["conds.name"].value!=""){
    	url+="?conds.name="+encodeURIComponent(form1["conds.name"].value);
    }
	callSynchronized(url,function(XML){//同步调用
	    productAjax=new AjaxObj();
	    productAjax.xml=XML.responseXML;
	    productAjax.menuId="productId";
	    productAjax.createMenu();
	});
	filterProduct();
}
/*查询当前产品目录下已关联的产品*/
function getRef(){
	callSynchronized("<s:url value="/business/product/viewNextproductRefSort.action"/>?conds.sort="+id,function(XML){//同步调用
	    refAjax=new AjaxObj();
	    refAjax.xml=XML.responseXML;
	    refAjax.menuId="refId";
	    refAjax.createMenu();
	});
}
/*已关联的产品从产品列表中过滤掉*/
function filterProduct(){
	for(i=$("productId").options.length-1;i>-1;i--){
		for(j=0;j<$("refId").options.length;j++){
			if($("productId").options[i].value==$("refId").options[j].value||$("productId").options[i].value==0){
				$("productId").remove(i);
				break;
			}
		}
	}
}
/*新增关联产品*/
function addProduct(){
	for(i=$("productId").options.length-1;i>-1;i--){
		if($("productId").options[i].selected==true){
		    var option=document.createElement("option");
	    	option.value=$("productId").options[i].value;
	    	option.text=$("productId").options[i].text;
			$("refId").add(option);
			$("productId").remove(i);
		}
	}
}
/*新增所有关联产品*/
function addAll(){
    if(!confirm("确定全部增加")){
    	return;
    }
	for(i=$("productId").options.length-1;i>-1;i--){
	    var option=document.createElement("option");
    	option.value=$("productId").options[i].value;
    	option.text=$("productId").options[i].text;
		$("refId").add(option);
		$("productId").remove(i);
	}
}
/*删除关联产品*/
function deleteProduct(){
	for(i=$("refId").options.length-1;i>-1;i--){
		if($("refId").options[i].selected==true){
		    var option=document.createElement("option");
	    	option.value=$("refId").options[i].value;
	    	option.text=$("refId").options[i].text;
			$("productId").add(option);
			$("refId").remove(i);
		}
	}
}
/*删除所有关联产品*/
function deleteAll(){
    if(!confirm("确定全部删除")){
    	return;
    }
	for(i=$("refId").options.length-1;i>-1;i--){
	    var option=document.createElement("option");
    	option.value=$("refId").options[i].value;
    	option.text=$("refId").options[i].text;
		$("productId").add(option);
		$("refId").remove(i);
	}
}
/*保存提交*/
function save(){
	var str="";
	for(i=$("refId").options.length-1;i>-1;i--){
    	str+=$("refId").options[i].value+",";
	}
	str=str.substring(0,str.length-1);
	form1.refIds.value=str;
	form1.submit();
}
</script>
		<script type="text/javascript"
			src="<s:url value="/script/selfResize.js"/>"></script>
		<script>
function initLoad(){
	f_iframeResize();
}
function initData(){
	initPage();
	initLoad();
}
window.onload = initData;
window.setInterval("initLoad()", 200);
</script>
	</head>

	<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
		<table width="980" border="0" cellspacing="0" cellpadding="0"
			align="center">
			<tr>
				<td background="<s:url value="/images/home_4a.gif"/>">
					<table width="100%" height="" border="0" cellspacing="0"
						cellpadding="0" align="center" bgcolor="#FFFFFF">
						<tr>
							<td valign="top" align="center">
								<br>
								<s:form id="form1"
									action="/business/product/su_saveproductRefSort.action"
									method="post">
									<input type="hidden" name="parentSort" value="${parentSort}">
									<input type="hidden" name="productRefSort.sort" value="">
									<table width="98%" border="0" cellspacing="0" cellpadding="0"
										background="<s:url value="/images/catalog_manage_8b.gif"/>">
										<tr>
											<td>
												<img src="<s:url value="/images/catalog_manage_8.gif"/>"
													width=668 height=11 alt="">
											</td>
										</tr>
										<tr>
											<td>
												<TABLE width="668" border="0" cellspacing="0"
													cellpadding="0"  class=tablecolor2>
													<tr>
														<td width="15%" height="50"  align="center">
															<div align="center">
																<a href="shareinfo.html" target="_blank">产品名称</a>
															</div>
														</td>
														<td width="35%"  align="center">
															<input name="conds.name" type="text"
																value="${conds.name}" size="30" />
														</td>
														<td  align="center"> 
															<input type="button" name="search"
																onclick="getProduct();" value="查 询">
															&nbsp;
															<input type="button" name="search" onclick="save()"
																value="保 存">&nbsp;
																<input type="button" value="返 回" onClick="pageBack()">
														</td>
													</tr>
												</TABLE>
												<table border="0"  width="668" >
													<tr>
														<td colspan="3">
															&nbsp;
															<font color="red">${returnMsg}</font>
														</td>
													</tr>
													<tr>
														<td valign="top" align="center">
															全部产品<br>
															<select name="productId" id="productId"
																style="width: 280px; height: 400px" property="id"
																labelProperty="name" multiple="multiple">
															</select>
														</td>
														<td aling="center" width="20" valign="middle">
															<input type="button" value="增加产品" onclick="addProduct()">
															<br>
															<input type="button" value="增加全部" onclick="addAll()">
															<br>
															<input type="button" value="删除产品"
																onclick="deleteProduct()">
															<br>
															<input type="button" value="删除全部" onclick="deleteAll()">
														</td>
														<td  align="center"valign="top" >
															已选产品<br>
															<select name="refId" id="refId"
																style="width: 280px; height: 400px" property="product"
																labelProperty="productName" multiple="multiple">
															</select>
														</td>
													</tr>
												</table>
											</td>
										</tr>
									</table>
								</s:form>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</body>
</html>
<script>
form1["productRefSort.sort"].value=id;
function pageBack(){
	window.parent.checkSort("${parentSort}");
}
</script>
